package com.zhoushihao.class0813;

import java.util.*;

public class BornYear {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int year = sc.nextInt();
        int n = sc.nextInt();
        Set<Character> set = new HashSet<>();
        for (int i = year; ; i++) {
            String newYear = String.format("%04d" , i);
//            System.out.println(newYear);
            for (int j = newYear.length() - 1; j >= 0; j--) {
                set.add(newYear.charAt(j));
            }
            if (set.size() == n) {
                System.out.println(i - year + " " + newYear);
                break;
            } else {
                set.clear();
            }
        }
    }
}
